package com.csdj.server.controller;


import com.csdj.server.pojo.*;
import com.csdj.server.service.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xyx
 * @since 2022-12-12
 */
@RestController
@RequestMapping("/employee/basic")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @Autowired
    private INationService nationService; //名族

    @Autowired
    private IPoliticsStatusService politicsStatusService; //政治面貌

    @Autowired
    private IJoblevelService joblevelService; //职称

    @Autowired
    private IPositionService positionService; //职位

    @Autowired
    private IDepartmentService departmentService; //部门

    @ApiOperation(value = "员工信息分页查询")
    @GetMapping("/")
    public RespPageBean getEmployeeByPage(@RequestParam(defaultValue = "1") Integer currentPage,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          Employee employee,
                                          LocalDate[] beginDateScope) {
        System.out.println(currentPage);
        System.out.println(size);
    return employeeService.getEmployeeByPage(currentPage, size, employee,beginDateScope);
    }

    @ApiOperation(value = "获取所有的名族")
    @GetMapping("/nations")
    public List<Nation> getAllNations(){
        return nationService.list();
    }

    @ApiOperation(value = "获取所有的政治面貌")
    @GetMapping("/politicsstatus")
    public List<PoliticsStatus> getAllPoliticsStatus(){
        return politicsStatusService.list();
    }

    @ApiOperation(value = "获取所有的职称")
    @GetMapping("/joblevels")
    public List<Joblevel> getAllJoblevels(){
        return joblevelService.list();
    }

    @ApiOperation(value = "获取所有的职位")
    @GetMapping("/positions")
    public List<Position> getAllPositions(){
        return positionService.list();
    }

    @ApiOperation(value = "获取所有的部门")
    @GetMapping("/departments")
    public List<Department> getAllDepartments(){
        return departmentService.getAllDepartmentById();
    }

    @ApiOperation(value = "获取最大工号")
    @GetMapping("/maxWordId")
    public RespBean getMaxWordId(){
        return employeeService.maxWorkId();
    }

    @ApiOperation(value = "添加员工信息")
    @PostMapping("/")
    public RespBean insertEmp(@RequestBody Employee employee){
        return employeeService.insertEmp(employee);
    }

    @ApiOperation(value = "修改员工信息")
    @PutMapping("/")
    public RespBean updateEmp(@RequestBody Employee employee){
        if(employeeService.updateById(employee)){
            return RespBean.success("修改成功!");
        }
        return RespBean.error("修改失败!");
    }

    @ApiOperation(value = "删除员工信息")
    @PutMapping("/{id}")
    public RespBean deleteEmp(@PathVariable("id") Integer id){
        if(employeeService.removeById(id)){
            return RespBean.success("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
}
